<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>WebSocket Chat</title>
</head>
<body>
<h1>WebSocket Chat</h1>
<div id="chat"></div>
<input id="message" placeholder="Enter message" type="text">
<button onclick="sendMessage()">Send</button>

<script>
    const ws = new WebSocket("ws://localhost:8089/chat/user");

    ws.onmessage = function (event) {
        const chat = document.getElementById("chat");
        const message = document.createElement("div");
        message.textContent = event.data;
        chat.appendChild(message);
    };

    function sendMessage() {
        const receiver = prompt("Enter receiver username:");
        const message = document.getElementById("message").value;
        if (receiver && message) {
            ws.send(receiver + ":" + message);
        }
    }
</script>
</body>
</html>